import time
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("https://www.baidu.com")
driver.maximize_window()
# id 选择器
print(driver.find_element(By.CSS_SELECTOR, "#kw").get_attribute("outerHTML"))
# class选择器
print(driver.find_element(By.CSS_SELECTOR, ".s_ipt").get_attribute("outerHTML"))
# 标签＋属性选择器
print(driver.find_element(By.CSS_SELECTOR, "input[name='wd']").get_attribute("outerHTML"))
# 层级
print(driver.find_element(By.CSS_SELECTOR, "form[id='form'] input").get_attribute("outerHTML"))
print("-"*50)
# 索引
ips = driver.find_elements(By.CSS_SELECTOR, "form[id='form'] input")
for i in ips:
    print(i.get_attribute("outerHTML"))
print("-"*50)
print(driver.find_element(By.CSS_SELECTOR, "form[id= 'form'] :nth-child(8)").get_attribute("outerHTML"))
# 查找的是父标签名下的第n个子标签
print(driver.find_element(By.CSS_SELECTOR, "form[id='form'] input:nth-of-type(8)").get_attribute("outerHTML"))
# 模糊匹配关键字
print(driver.find_element(By.CSS_SELECTOR, "input[name*='_idx']").get_attribute("outerHTML"))
# 多条件查询
print(driver.find_element(By.CSS_SELECTOR, "input[name='wd'][id='kw']").get_attribute("outerHTML"))



driver.quit()